home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  12.8 KB  |  562 lines

  1. /* Stuff heavily dependent on the configuration info in config.h */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "proc.h"
  8. #include "cmdparse.h"
  9. #include "config.h"
  10. #include "daemon.h"
  11. #include "timer.h"
  12. #include "iface.h"
  13. #include "ppp.h"
  14. #include "slip.h"
  15. #include "usock.h"
  16. #include "socket.h"
  17. #include "kiss.h"
  18. #include "enet.h"
  19. #include "ax25.h"
  20. #include "netrom.h"
  21. #include "ip.h"
  22. #include "tcp.h"
  23. #include "udp.h"
  24. #include "commands.h"
  25. #include "rspf.h"
  26.  
  27. static int dostart __ARGS((int argc,char *argv[],void *p));
  28. static int dostop __ARGS((int argc,char *argv[],void *p));
  29. static int domessage __ARGS((int argc,char *argv[],void *p));
  30.  
  31. struct mbuf *Hopper;
  32. unsigned Nsessions = NSESSIONS;
  33. int32 Heapsize = HEAPSIZE * (long)1024;
  34.  
  35. /* Free memory threshold, below which things start to happen to conserve
  36.  * memory, like issuing source quenches and refusing connects
  37.  */
  38. int32 Memthresh = MTHRESH;
  39.  
  40. /* daemons to be run at startup time */
  41. struct daemon Daemons[] = {
  42.     "killer",    200,    killer,
  43.     "timer",    1024,    timerproc,
  44.     "network",    1536,    network,
  45.     "keyboard",    250,    keyboard,
  46.     NULLCHAR,    0,    NULLVFP
  47. };
  48.  
  49. struct iftype Iftypes[] = {
  50.     /* This entry must be first, since Loopback refers to it */
  51.     "None",        NULL,        NULL,        NULL,
  52.     NULL,        TYPE_NONE,    0,
  53.  
  54. #ifdef    AX25
  55.     "AX25",        ax_send,    ax_output,    pax25,
  56.     setcall,    TYPE_AX25,    AXALEN,
  57. #endif
  58.  
  59. #ifdef    SLIP
  60.     "SLIP",        slip_send,    NULL,        NULL,
  61.     NULL,        TYPE_IP,    0,
  62. #endif
  63.  
  64. #ifdef    ETHER
  65.     /* Note: NULL is specified for the scan function even though
  66.      * gether() exists because the packet drivers don't support
  67.      * address setting.
  68.      */
  69.     "Ethernet",    enet_send,    enet_output,    pether,
  70.     NULL,        TYPE_ETHER,    EADDR_LEN,
  71. #endif
  72.  
  73. #ifdef    NETROM
  74.     "NETROM",    nr_send,    NULL,        pax25,
  75.     setcall,    TYPE_NETROM,    AXALEN,
  76. #endif
  77. #ifdef PPP
  78.     "PPP",        ppp_send,    ppp_output,    NULL,
  79.     NULL,        TYPE_PPP,        0,
  80. #endif    /* PPP */
  81.  
  82.     NULLCHAR
  83. };
  84.  
  85. /* Command lookup and branch tables */
  86. struct cmds Cmds[] = {
  87.     /* The "go" command must be first */
  88.     "",        go,        0, 0, NULLCHAR,
  89.     "abort",    doabort,    0, 0, NULLCHAR,
  90.     "amiga",    doamiga,    0, 0, NULLCHAR,
  91. #if    (defined(AX25) || defined(ETHER) || defined(APPLETALK))
  92.     "arp",        doarp,        0, 0, NULLCHAR,
  93. #endif
  94. #ifdef    ASY
  95.     "asystat",    doasystat,    0, 0, NULLCHAR,
  96. #endif
  97.     "attach",    doattach,    0, 2,
  98.         "attach <hardware> <hw specific options>",
  99. #ifdef    AX25
  100.     "ax25",        doax25,        0, 0, NULLCHAR,
  101. #endif    
  102. #ifdef    MAILBOX
  103.     "bbs",        dobbschat,    1024, 0, NULLCHAR,
  104. #endif
  105. /* This one is out of alpabetical order to allow abbreviation to "c" */
  106. #ifdef    AX25
  107.     "connect",    doconnect,    1024, 3,"connect <interface> <callsign>",
  108. #endif
  109. #ifdef    CHATNODE
  110.     "chatnode",    dobbschat,    1024, 0, NULLCHAR,
  111. #endif
  112.     "close",    doclose,    0, 0, NULLCHAR,
  113.     "disconnect",    doclose,    0, 0, NULLCHAR,
  114. #ifdef    DIGGER
  115.     "digger",    dodigger,    0, 0, NULLCHAR,
  116. #endif
  117.     "detach",    dodetach,    0, 2, "detach <interface>",
  118.     "domain",    dodomain,    0, 0, NULLCHAR,
  119.     "echo",        doecho,        0, 0, NULLCHAR,
  120.     "eol",        doeol,        0, 0, NULLCHAR,
  121.     "escape",    doescape,    0, 0, NULLCHAR,
  122.     "exit",        doexit,        0, 0, NULLCHAR,
  123.     "finger",    dofinger,    1024, 2, "finger name@host",
  124.     "ftp",        doftp,        2048, 2, "ftp <address>",
  125. #ifdef FTPTDISC
  126.     "fttimeout",    doftptdisc,    0, 0, NULLCHAR,
  127. #endif
  128.     "ftpdown",    doftpdown,    0, 0, NULLCHAR,
  129.     "help",        dohelp,        0, 0, NULLCHAR,
  130.     "hopcheck",    dohop,        0, 0, NULLCHAR,
  131.     "hostname",    dohostname,    0, 0, NULLCHAR,
  132.     "icmp",        doicmp,        0, 0, NULLCHAR,
  133.     "ifconfig",    doifconfig,    0, 0, NULLCHAR,
  134.     "ip",        doip,        0, 0, NULLCHAR,
  135.     "kick",        dokick,        0, 0, NULLCHAR,
  136.     "less",        doless,        512, 2, "less <filename>",
  137. #ifdef    MAILBOX
  138.     "mbox",        dombox,        0, 0, NULLCHAR,
  139. #endif
  140.     "mem",        domem,        0, 0, NULLCHAR,
  141.     "message",    domessage,    0, 2, "message <socket> <msg>",
  142. #ifdef    AX25
  143.     "mode",        domode,        0, 2, "mode <interface>",
  144. #endif
  145. #ifdef    NETROM
  146.     "netrom",    donetrom,    0, 0, NULLCHAR,
  147. #ifdef    NRS
  148.     "nrstat",    donrstat,    0, 0, NULLCHAR,
  149. #endif    /* NRS */
  150. #endif    /* NETROM */
  151. #ifdef    NNTP
  152.     "nntp",        donntp,        0, 0, NULLCHAR,
  153. #endif
  154.     "param",    doparam,    0, 2, "param <interface>",
  155.     "ping",        doping,        512, 2, "ping <host> [<length> [<interval> [incflag]]]",
  156. #ifdef    POP
  157.     "pop",        dopop,        0, 0, NULLCHAR,
  158. #endif
  159. #ifdef PPP
  160.     "ppp",        dopppcontrol,    0, 0, NULLCHAR,
  161. #endif    /* PPP */
  162.     "ps",        ps,        0, 0, NULLCHAR,
  163.     "record",    dorecord,    0, 0, NULLCHAR,
  164.     "remote",    doremote,    0, 3, "remote [-p port] [-k key] [-a kickaddr] <address> exit|reset|kick",
  165.     "reset",    doreset,    0, 0, NULLCHAR,
  166. #ifdef    RLOGINCLI
  167.     "rlogin",    dorlogin,    2048, 2, "rlogin <address>",
  168. #endif
  169. #ifdef    RIP
  170.     "rip",        dorip,        0, 0, NULLCHAR,
  171. #endif
  172.     "route",    doroute,    0, 0, NULLCHAR,
  173. #ifdef    RSPF
  174.     "rspf",        dorspf,        0, 0, NULLCHAR,
  175. #endif    /* RSPF */
  176.     "session",    dosession,    0, 0, NULLCHAR,
  177.     "smtp",        dosmtp,        0, 0, NULLCHAR,
  178.     "socket",    dosock,        0, 0, NULLCHAR,
  179.     "source",    dosource,    0, 2, "source <filename>",
  180. #ifdef    SERVERS
  181.     "start",    dostart,    0, 2, "start <servername>",
  182.     "stop",        dostop,        0, 2, "stop <servername>",
  183. #endif
  184.     "status",    dostatus,    0, 0, NULLCHAR,
  185.     "tcp",        dotcp,        0, 0, NULLCHAR,
  186.     "telnet",    dotelnet,    1024, 2, "telnet <address>",
  187. #ifdef    TRACE
  188.     "trace",    dotrace,    0, 0, NULLCHAR,
  189. #endif
  190.     "ttylink",    dotelnet,    1024, 2, "ttylink <address>",
  191.     "udp",        doudp,        0, 0, NULLCHAR,
  192.     "upload",    doupload,    0, 0, NULLCHAR,
  193.     "?",        dohelp,        0, 0, NULLCHAR,
  194.     NULLCHAR,    NULLFP,        0, 0,
  195.         "Unknown command; type \"?\" for list",
  196. };
  197.  
  198. /* List of supported hardware devices */
  199. struct cmds Attab[] = {
  200. #ifdef    PC_EC
  201.     /* 3-Com Ethernet interface */
  202.     "3c500", ec_attach, 0, 7, 
  203.     "attach 3c500 <address> <vector> arpa <label> <buffers> <mtu> [ip_addr]",
  204. #endif
  205. #ifdef    ASY
  206.     /* Ordinary PC asynchronous adaptor */
  207.     "asy", asy_attach, 0, 8, 
  208. #ifndef    AMIGA
  209.     "attach asy <address> <vector> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]",
  210. #else
  211.      "attach asy <driver> <unit> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]",
  212. #endif    /* AMIGA */
  213. #endif    /* ASY */
  214. #ifdef    KISS
  215.     /* Multi-port KISS interface piggy-backing on ASY interface. */
  216.     "kiss", kiss_attach, 0, 4, 
  217.     "attach kiss <asy_interface_label> <port> <label> [mtu]",
  218. #endif    /* KISS */
  219. #ifdef    PC100
  220.     /* PACCOMM PC-100 8530 HDLC adaptor */
  221.     "pc100", pc_attach, 0, 8, 
  222.     "attach pc100 <address> <vector> ax25 <label> <buffers>\
  223.  <mtu> <speed> [ip_addra] [ip_addrb]",
  224. #endif
  225. #ifdef    DRSI
  226.     /* DRSI PCPA card in low speed mode */
  227.     "drsi", dr_attach, 0, 8,
  228.     "attach drsi <address> <vector> ax25 <label> <bufsize> <mtu>\
  229. <chan a speed> <chan b speed> [ip addr a] [ip addr b]",
  230. #endif
  231. #ifdef    EAGLE
  232.     /* EAGLE RS-232C 8530 HDLC adaptor */
  233.     "eagle", eg_attach, 0, 8,
  234.     "attach eagle <address> <vector> ax25 <label> <buffers>\
  235.  <mtu> <speed> [ip_addra] [ip_addrb]",
  236. #endif
  237. #ifdef    HAPN
  238.     /* Hamilton Area Packet Radio (HAPN) 8273 HDLC adaptor */
  239.     "hapn", hapn_attach, 0, 8,
  240.     "attach hapn <address> <vector> ax25 <label> <rx bufsize>\
  241.  <mtu> csma|full [ip_addr]",
  242. #endif
  243. #ifdef    APPLETALK
  244.     /* Macintosh AppleTalk */
  245.     "0", at_attach, 0, 7,
  246.     "attach 0 <protocol type> <device> arpa <label> <rx bufsize> <mtu> [ip_addr]",
  247. #endif
  248. #ifdef NETROM
  249.     /* fake netrom interface */
  250.     "netrom", nr_attach, 0, 1,
  251.     "attach netrom [ip_addr]",
  252. #endif
  253. #ifdef    PACKET
  254.     /* FTP Software's packet driver spec */
  255.     "packet", pk_attach, 0, 4,
  256.     "attach packet <int#> <label> <buffers> <mtu> [ip_addr]",
  257. #endif
  258. #ifdef    HS
  259.     /* Special high speed driver for DRSI PCPA or Eagle cards */
  260.     "hs", hs_attach, 0, 7,
  261.     "attach hs <address> <vector> ax25 <label> <buffers> <mtu>\
  262.  <txdelay> <persistence> [ip_addra] [ip_addrb]",
  263. #endif
  264. #ifdef SCC
  265.     "scc", scc_attach, 0, 7,
  266.      "\nattach scc <devices> init <addr> <spacing> <Aoff> <Boff> <Dataoff>\
  267. \n   <intack> <vec> [p]<clock> [hdwe] [param]\
  268. \nattach scc <chan> slip|kiss|nrs|ax25 <label> <mtu> <speed> <bufsiz> [call] ",
  269.   #endif
  270.     NULLCHAR,
  271. };
  272.  
  273. /* Packet tracing stuff */
  274. #include "trace.h"
  275. #ifdef    TRACE
  276.  
  277. /* Protocol tracing function pointers. Matches list of TYPE definitions
  278.  * in iface.h.
  279.  */
  280. struct trace Tracef[] = {
  281. #ifdef    AX25
  282.     ax_forus,    ax25_dump,    /* TYPE_AX25 */
  283. #else
  284.     NULLFP,        NULLVFP,
  285. #endif    /* AX25 */
  286.  
  287. #ifdef    ETHER                /* TYPE_ETHER */
  288.     ether_forus,    ether_dump,
  289. #else
  290.     NULLFP,        NULLVFP,
  291. #endif    /* ETHER */
  292.  
  293.     NULLFP,        ip_dump,    /* TYPE_IP */
  294.  
  295. #ifdef    APPLETALK
  296.     at_forus,    at_dump,    /* TYPE_APPLETALK */
  297. #else
  298.     NULLFP,        NULLVFP,
  299. #endif    /* APPLETALK */
  300.  
  301. #ifdef    KISS                /* TYPE_KISS */
  302.     ki_forus,    ki_dump,
  303. #else
  304.     NULLFP,        NULLVFP,
  305. #endif    /* KISS */
  306.  
  307. #ifdef    NETROM                /* TYPE_NETROM */
  308.     NULLFP,        ip_dump,
  309. #else
  310.     NULLFP,        NULLVFP,
  311. #endif    
  312.  
  313.     NULLFP,        ip_dump,    /* TYPE_NONE */
  314.     NULLFP,        ip_dump,    /* TYPE_SLIP */
  315.  
  316. #ifdef PPP
  317.     NULLFP,        ppp_dump,    /* TYPE_PPP */
  318. #else
  319.     NULLFP,        NULLVFP,
  320. #endif /* PPP */
  321. };
  322.  
  323. #else    /* TRACE */
  324.  
  325. /* Stubs for tracing disabled */
  326. struct trace Tracef[] = {
  327.     NULLFP        /* No tracing at all */
  328. };
  329.  
  330. void
  331. dump(iface,direction,type,bp)
  332. struct iface *iface;
  333. int direction;
  334. unsigned type;
  335. struct mbuf *bp;
  336. {
  337. }
  338. #endif    /* TRACE */
  339.  
  340.  
  341. #if    defined(AX25) && !defined(NETROM)
  342. /* Stubs for when ax25 is configured wihtout net/rom */
  343. void
  344. nr_route(bp,iaxp)
  345. struct mbuf *bp;
  346. struct ax25_cb *iaxp;
  347. {
  348.     free_p(bp);
  349. }
  350. void
  351. nr_nodercv(iface,source,bp)
  352. struct iface *iface;
  353. char *source;
  354. struct mbuf *bp;
  355. {
  356.     free_p(bp);
  357. }
  358. #endif    /* defined(AX25) && !defined(NETROM) */
  359.  
  360.  
  361. #ifndef    RIP
  362. /* Stub for routing timeout when RIP is not configured -- just remove entry */
  363. void
  364. rt_timeout(s)
  365. void *s;
  366. {
  367.     struct route *stale = (struct route *)s;
  368.  
  369.     rt_drop(stale->target,stale->bits);
  370. }
  371. #endif
  372.  
  373. #ifdef    SERVERS
  374. /* "start" and "stop" subcommands */
  375. static struct cmds Startcmds[] = {
  376. #if    defined(AX25) && defined(MAILBOX)
  377.     "ax25",        ax25start,    256, 0, NULLCHAR,
  378. #endif
  379. #ifdef    CHATNODE
  380.     "chatnode",    conv1,    384, 0, NULLCHAR,
  381. #endif
  382.     "discard",    dis1,        256, 0, NULLCHAR,
  383.     "echo",        echo1,        256, 0, NULLCHAR,
  384.     "finger",    finstart,    256, 0, NULLCHAR,
  385.     "ftp",        ftpstart,    256, 0, NULLCHAR,
  386. #if    defined(NETROM) && defined(MAILBOX)
  387.     "netrom",    nr4start,    256, 0, NULLCHAR,
  388. #endif
  389. #ifdef    POP
  390.     "pop",        pop1,        256, 0, NULLCHAR,
  391. #endif
  392. #ifdef    RIP
  393.     "rip",        doripinit,    0,   0, NULLCHAR,
  394. #endif
  395.     "smtp",        smtp1,        256, 0, NULLCHAR,
  396. #if    defined(MAILBOX)
  397.     "telnet",    telnet1,    256, 0, NULLCHAR,
  398. #endif
  399.     "ttylink",    ttylstart,    256, 0, NULLCHAR,
  400.     "remote",    rem1,        256, 0, NULLCHAR,
  401.     NULLCHAR,
  402. };
  403. static struct cmds Stopcmds[] = {
  404. #if    defined(AX25) && defined(MAILBOX)
  405.     "ax25",        ax250,        0, 0, NULLCHAR,
  406. #endif
  407. #ifdef    CHATNODE
  408.     "chatnode",    conv0,        0, 0, NULLCHAR,
  409. #endif
  410.     "discard",    dis0,        0, 0, NULLCHAR,
  411.     "echo",        echo0,        0, 0, NULLCHAR,
  412.     "finger",    fin0,        0, 0, NULLCHAR,
  413.     "ftp",        ftp0,        0, 0, NULLCHAR,
  414. #if    defined(NETROM) && defined(MAILBOX)
  415.     "netrom",    nr40,        0, 0, NULLCHAR,
  416. #endif
  417. #ifdef    POP
  418.     "pop",        pop0,        0, 0, NULLCHAR,
  419. #endif
  420. #ifdef    RIP
  421.     "rip",        doripstop,    0, 0, NULLCHAR,
  422. #endif
  423.     "smtp",        smtp0,        0, 0, NULLCHAR,
  424. #ifdef    MAILBOX
  425.     "telnet",    telnet0,    0, 0, NULLCHAR,
  426. #endif
  427.     "ttylink",    ttyl0,        0, 0, NULLCHAR,
  428.     "remote",    rem0,        0, 0, NULLCHAR,
  429.     NULLCHAR,
  430.  
  431. };
  432.  
  433. static int
  434. dostart(argc,argv,p)
  435. int argc;
  436. char *argv[];
  437. void *p;
  438. {
  439.     return subcmd(Startcmds,argc,argv,p);
  440. }
  441.  
  442. static int
  443. dostop(argc,argv,p)
  444. int argc;
  445. char *argv[];
  446. void *p;
  447. {
  448.     return subcmd(Stopcmds,argc,argv,p);
  449. }
  450. #endif    /* SERVERS */
  451.  
  452. /* Various configuration-dependent functions */
  453.  
  454. /* Process packets in the Hopper */
  455. static void
  456. network(i,v1,v2)
  457. int i;
  458. void *v1;
  459. void *v2;
  460. {
  461.     struct mbuf *bp;
  462.     struct phdr phdr;
  463.     char i_state;
  464.  
  465. loop:    i_state = dirps();
  466.     while(Hopper == NULLBUF)
  467.         pwait(&Hopper);
  468.     restore(i_state);
  469.  
  470.     /* Process the input packet */
  471.     bp = dequeue(&Hopper);
  472.     pullup(&bp,(char *)&phdr,sizeof(phdr));
  473.     if(phdr.iface != NULLIF)
  474.         phdr.iface->rawrecvcnt++;
  475.     dump(phdr.iface,IF_TRACE_IN,phdr.type,bp);
  476.     switch(phdr.type){
  477. #ifdef    KISS
  478.     case TYPE_KISS:
  479.         kiss_recv(phdr.iface,bp);
  480.         break;
  481. #endif
  482. #ifdef    AX25
  483.     case TYPE_AX25:
  484.         ax_recv(phdr.iface,bp);
  485.         break;
  486. #endif
  487. #ifdef    ETHER
  488.     case TYPE_ETHER:
  489.         eproc(phdr.iface,bp);
  490.         break;
  491. #endif
  492. #ifdef PPP
  493.     case TYPE_PPP:
  494.         pproc(phdr.iface,bp);
  495.         break;
  496. #endif    /* PPP */
  497.     /* These types have no link layer protocol at the point when they're
  498.      * put in the hopper, so they can be handed directly to IP. The
  499.      * separate types are just for user convenience when running the
  500.      * "iface" command.
  501.      */
  502.     case TYPE_NETROM:
  503.     case TYPE_SLIP:
  504.     case TYPE_IP:
  505.     case TYPE_NONE:
  506.         ip_route(phdr.iface,bp,0);
  507.         break;
  508.     case TYPE_APPLETALK:
  509.     default:
  510.         free_p(bp);
  511.         break;
  512.     }
  513.     /* Let everything else run - this keeps the system from wedging
  514.      * when we're hit by a big burst of packets
  515.      */
  516.     pwait(NULL);
  517.     goto loop;
  518. }
  519.  
  520. static int
  521. domessage(argc,argv,p)
  522. int argc;
  523. char *argv[];
  524. void *p;
  525. {
  526.     char msg[256];
  527.     int sock[DEFNSOCK];
  528.     int count, i;
  529.  
  530.     /* command takes the form:
  531.  
  532.         message <one or more socket numbers> <message>
  533.  
  534.     the procedure constructs a list of socket numbers from the input
  535.     arguments, and constructs the message from the first argument that
  536.     is not a valid socket number */
  537.  
  538.     count = (argc < DEFNSOCK - 1) ? argc : DEFNSOCK -1;
  539.  
  540.     /* get socket args */
  541.     for (i=1; i<count ; i++)
  542.         if((sock[i] = atoi(argv[i])) == 0)
  543.             break;
  544.  
  545.     count = i;
  546.     msg[0] = '\0';
  547.  
  548.     /* collect rest of args as message */
  549.     for (;i<argc;i++) {
  550.         strcat(msg,argv[i]);
  551.         strcat(msg," ");
  552.     }
  553.  
  554.     /* output to all sockets */
  555.     for (i=1; i<count; i++)    {
  556.         usprintf(sock[i],"\a\n*** Message from %s:\n%s\n",Hostname,msg);
  557.         usflush(sock[i]);
  558.     }
  559.     return 0;
  560. }
  561.  
  562.